<%@ page language="java" contentType="application/octet-stream;charset=utf-8" %>
<%@ include file="/home/include/init_home.jsp" %>
<%@ page import="com.welfare.home.*" %>
<%@ page import="com.zll.framework.db.*" %>
<%
	out.clear();
	out = pageContext.pushBody(); 
	
	String excelTitle = "복지서비스목록";
	
	response.setHeader("Content-Disposition","attachment;filename="+java.net.URLEncoder.encode(excelTitle, "utf-8")+"_"+StringUtil.today()+".xls");
	response.setHeader("Content-Description","JSP Generated Data");
	
	

	HashBox box = new HashBox(request);	

	
	
	/* 파라미터 */
	String ty					= StringUtil.nvl(request.getParameter("ty"),"k");	//검색종류 k:키워드, s:간편검색, d:상세검색, p:프로그램검색
	
	
	/* 키워드검색 */
	String keyword_col			= StringUtil.nvl(request.getParameter("keyword_col"), "service_name");
	String keyword				= StringUtil.nvl(request.getParameter("keyword"));
	
	/* 간편검색 */
	String s_age				= StringUtil.nvl(request.getParameter("s_age"));
	String s_birth				= StringUtil.nvl(request.getParameter("s_birth"));
	String s_family				= StringUtil.nvl(request.getParameter("s_family"));
	String s_income				= box.getCheckedValue("s_income");
	String s_srch_target		= box.getCheckedValue("s_srch_target");
	
	/* 상세검색 */
	String d_service_type		= box.getCheckedValue("d_service_type");
	String d_owner_code			= box.getCheckedValue("d_owner_code");
	String d_srch_age			= box.getCheckedValue("d_srch_age");
	String d_srch_target		= box.getCheckedValue("d_srch_target");
	String d_srch_family		= box.getCheckedValue("d_srch_family");
	String d_srch_income		= box.getCheckedValue("d_srch_income");
	String d_srch_support		= box.getCheckedValue("d_srch_support");
	String d_srch_needs		= box.getCheckedValue("d_srch_needs");
	
	/* 교육프로그램검색 */
	String p_srch_age			= box.getCheckedValue("p_srch_age");
	String p_prg_period			= box.getCheckedValue("p_prg_period");
	String p_srch_prg_time		= box.getCheckedValue("p_srch_prg_time");
	String p_srch_prg_weekday	= box.getCheckedValue("p_srch_prg_weekday");
	String p_service_name		= StringUtil.nvl(request.getParameter("p_service_name"));
	String p_dept_name			= StringUtil.nvl(request.getParameter("p_dept_name"));
	
	String order_col			= "hit_count desc, service_id desc";
	
	HashMap infos = new HashMap();
	infos.put("ty",				ty);
	infos.put("order_col", 		order_col);
	
	//키워드
	if ("k".equals(ty)) {
		if ("service_name".equals(keyword_col)) {
			infos.put("keyword_col",	keyword_col);
			infos.put("service_name",	keyword);
			infos.put("order_col", 		"hit_count desc, service_id desc");
		} else {
			infos.put("keyword_col",	"");
			infos.put("keyword",		keyword);
			infos.put("order_col", 		"srt, hit_count desc, service_id desc");
		}
	}
	//간편검색
	infos.put("s_age", 			CommonUtil.convertSrchAge(s_age));
	infos.put("s_birth",		s_birth);
	infos.put("s_family",		s_family);
	infos.put("s_income",		s_income);
	infos.put("s_srch_target",	s_srch_target);
	//상세검색
	infos.put("d_service_type", d_service_type);
	infos.put("d_owner_code", 	d_owner_code);
	infos.put("d_srch_age",	 	d_srch_age);
	infos.put("d_srch_target", 	d_srch_target);
	infos.put("d_srch_family", 	d_srch_family);
	infos.put("d_srch_income", 	d_srch_income);
	infos.put("d_srch_support", d_srch_support);
	infos.put("d_srch_needs", 	d_srch_needs);
	//교육프로그램검색
	if (ty.equals("p")) {
		infos.put("service_gubn",	"02");
	}
	infos.put("p_srch_age", 			CommonUtil.convertSrchAgeByCode(p_srch_age));
	infos.put("p_prg_period", 			p_prg_period);
	infos.put("p_srch_prg_time",	 	p_srch_prg_time);
	infos.put("p_srch_prg_weekday", 	p_srch_prg_weekday);
	infos.put("p_service_name", 		p_service_name);
	infos.put("p_dept_name", 			p_dept_name);
	


	HomeDAO dao 	= new HomeDAO();
	
	HashList list 	= dao.selectServiceList(infos);

	list.setHeader("service_type", 	"유형", 		MetaData.ALIGN_CENTER);
	list.setHeader("service_name", 	"서비스명",	MetaData.ALIGN_LEFT);
	list.setHeader("dept_name", 	"제공기관",	MetaData.ALIGN_LEFT);
	list.setHeader("tel_no", 		"연락처",	MetaData.ALIGN_LEFT);
	list.setHeader("hit_count", 	"조회수",	MetaData.ALIGN_RIGHT);
	
	list.writeToExcel(response, excelTitle);
%>
